home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr44 / frasrc19.zip / F16.C < prev    next >
C/C++ Source or Header  |  1994-08-18  |  3KB  |  91 lines

  1. /**************************************
  2. **
  3. ** F16.C : Code to read 16-bit fractal data sets.  Uses
  4. ** strictly Targa16 type 10 files (run-length encoded 16-bit RGB).
  5. */
  6.  
  7. /* Lee Daniel Crocker       CompuServe: 73407,2030   <== Preferred
  8. ** 1380 Jewett Ave.          BIX: lcrocker
  9. ** Pittsburg, CA  94565        Usenet: ...!ames!pacbell!sactoh0!siva!lee
  10. **
  11. ** This code is hereby placed in the public domain.  You are free to
  12. ** use, modify, usurp, laugh at, destroy, or otherwise abuse it in any
  13. ** way you see fit.
  14. **
  15. ** "If you steal from one author it's plagiarism; if you steal from
  16. ** many it's research."  --Wilson Mizner
  17. */
  18.  
  19. /* 16 bit .tga files were generated for continuous potential "potfile"s
  20.    from version 9.? thru version 14.  Replaced by double row gif type
  21.    file (.pot) in version 15.  Delete this code after a few more revs.
  22.    The part which wrote 16 bit .tga files has already been deleted.
  23. */
  24.  
  25. #include <stdio.h>
  26. #include <string.h>
  27. #include <ctype.h>
  28. #include "targa_lc.h"
  29. #include "prototyp.h"
  30.  
  31. #ifdef XFRACT
  32. char rlebuf[258];    /* RLE-state variables */
  33. #endif
  34. static int state, count, bufp;
  35.  
  36. /**************************************
  37. **
  38. ** Open previously saved Targa16 type 10 file filling in hs, vs, and
  39. ** csize with values in the header.  If *csize is not zero, the block
  40. ** pointed to by cp is filled with the comment block.  The caller
  41. ** _must_ allocate 256 bytes for this purpose before calling.
  42. */
  43.  
  44. FILE *t16_open(char *fname, int *hs, int *vs, int *csize, U8 *cp)
  45. {
  46.     char filename[64];
  47.     U8 header[HEADERSIZE];
  48.     FILE *fp;
  49.  
  50.     strcpy(filename, fname);
  51.     if (strchr(filename, '.') == NULL) strcat(filename, ".TGA");
  52.     if ((fp = fopen(filename, READMODE)) == NULL) return NULL;
  53.  
  54.     fread(header, HEADERSIZE, 1, fp);
  55.     if ((header[O_FILETYPE] != T_RLERGB) || (header[O_ESIZE] != 16)) {
  56.     fclose(fp);
  57.     return NULL;
  58.     }
  59.     GET16(header[O_HSIZE], *hs);
  60.     GET16(header[O_VSIZE], *vs);
  61.     if ((*csize = header[O_COMMENTLEN]) != 0) fread(cp, *csize, 1, fp);
  62.  
  63.     state = count = bufp = 0;
  64.     return fp;
  65. }
  66.  
  67. int t16_getline(FILE *fp, int hs, U16 *data)
  68. {
  69.     int i;
  70.  
  71.     for (i=0; i<hs; ++i) {
  72.     if (state == 0) {
  73.         bufp = 0;
  74.         if ((count = getc(fp)) > 127) {
  75.         state = 1;
  76.         count -= 127;
  77.         fread(rlebuf, 2, 1, fp);
  78.         } else {
  79.         state = 2;
  80.         ++count;
  81.         fread(rlebuf, 2, count, fp);
  82.         }
  83.     }
  84.     GET16(rlebuf[bufp], data[i]);
  85.     if (--count == 0) state = 0;
  86.     if (state == 2) bufp += 2;
  87.     }
  88.     return 0;
  89. }
  90.  
  91.